package experiment2;

import java.util.Arrays;

/**
 * @author mazouri
 * @create 2021-10-09 10:48
 */
public class InsertSort {
    private int[] v;

    public void sort() {
        insertSort(0);
    }

    public void insertSort(int begin) {
        if (begin == v.length) return;

        int temp = v[begin];
        while (begin > 0 && temp < v[begin - 1]) {
            v[begin] = v[begin - 1];
            begin--;
        }

        v[begin] = temp;
        insertSort(begin + 1);
    }

    public static void main(String[] args) {
        InsertSort sort = new InsertSort();
        sort.v = new int[]{44,3, 38, 5, 47,5, 15};
        sort.sort();
        System.out.println(Arrays.toString(sort.v));
    }
}
